<?php

namespace App\Models\Traits;

use App\Models\Comment;
use App\Models\Like;
use App\Models\Support;
use Illuminate\Database\Eloquent\Relations\HasMany;

trait HasLikes
{
    public function getLikesShowAttribute(): string
    {
        return sprintf('%s / %s', $this->likes()->count(), $this->likes()->sum('polls'));
    }

    public function likes(): HasMany
    {
        return $this->hasMany(Like::class);
    }

    public function getCommentsShowAttribute(): string
    {
        return sprintf('%s / %s', $this->comments()->count(), $this->comments()->sum('polls'));
    }

    public function comments(): HasMany
    {
        return $this->hasMany(Comment::class);
    }

    public function getSupportsShowAttribute(): string
    {
        return sprintf(
            '%s / %s / %s',
            $this->supports()->count(),
            $this->supports()->sum('amount'),
            $this->supports()->sum('polls')
        );
    }

    public function supports(): HasMany
    {
        return $this->hasMany(Support::class);
    }
}
